# -*- coding: utf-8 -*-

import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from BeautifulSoup import BeautifulSoup
from xmw.tianya import bot


from xmw.tianya import error_tianya
import os
import urllib2
import uuid

import datetime

from google.appengine.ext import webapp

class MainPage(webapp.RequestHandler):
  def get(self):
      page = urllib2.urlopen("http://cache.tianya.cn/techforum/content/516/39685.shtml")
      soup = BeautifulSoup(page,fromEncoding="GB18030")
      #print soup.prettify()
      page.close()
      
      #title in utf-8
      print soup.html.body.title.contents
      apn_inputs=soup.findAll('input',{'name':'apn'})
      page_urls=apn_inputs[0]
      print dir(page_urls)
      print page_urls
      value =page_urls["value"]
      print value
      print dir(value)
      print value.split(',')

      
      self.response.headers['Content-Type'] = 'text/plain'
      self.response.out.write('OK')

def main():
    application = webapp.WSGIApplication(
                                       [('/scan_page', MainPage)],
                                       debug=True)
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()